import { Base64 } from 'js-base64';
const LANG = {
    PREFIX: '~`~`',
    SPLITTER: '`~`',
    SUFFIX: '`~`~',
};
const getCurrentLabel = function (multiStr, currentLanguageId = '7') {
    const localeLanguageId = currentLanguageId;
    const list = {};
    if (typeof multiStr === 'string' && multiStr.indexOf(LANG.PREFIX) > -1) {
        multiStr = multiStr.substring(4);
        multiStr = multiStr.substring(0, multiStr.length - 4);
        multiStr.split(LANG.SPLITTER).map((item) => {
            list[item.substr(0, 2).replace(' ', '')] = item.substr(2);
        });
        return list[localeLanguageId] ? list[localeLanguageId] : '';
    }
    else {
        return multiStr;
    }
};
const getMultiStrFromBase64 = function (baseStr) {
    if (baseStr.indexOf('base64_') > -1) {
        let resultMulti = '';
        resultMulti = baseStr.substr(7);
        return Base64.decode(resultMulti);
    }
    else {
        return baseStr;
    }
};

const changeEncodeCurrentLabel = function (old_str, str, currentLanguageId = '7') {// ~`~`7 中文`~`8 English`~`9 繁体`~`~
    const list = {};
    if (typeof old_str === 'string' && old_str.indexOf(LANG.PREFIX) > -1) {
        let reg = new RegExp(currentLanguageId + ".+?\`\~")
        let subStr = old_str.match(reg);
        str == "" ? str = old_str.replace(old_str.match(reg), "") : str = old_str.replace(old_str.match(reg), currentLanguageId + ` ` + str + "`~");
    }
    return "base64_"+Base64.encode(str)
}
export { getCurrentLabel, getMultiStrFromBase64, changeEncodeCurrentLabel };
